package com.hdaccp.goodsprovider.controller;

import com.hdaccp.goodsprovider.dao.GsizeDao;
import org.main.bean.POJO.PGoods;
import org.main.bean.POJO.PGsize;
import org.main.bean.entity.Gsize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * By： 土豆菌
 * 2019/2/28 10:17
 */

@RestController
@RequestMapping("/gsizeInfo")
public class GsizeController {
    @Autowired
    private GsizeDao gsizeDao;

    @RequestMapping("/query")
    public List<Gsize>query(){
        return gsizeDao.findAll();
    }

    @RequestMapping("/getOne/{id}")
    public Gsize getOne(@PathVariable("id") int id){

        return gsizeDao.getOne(id);
    }

    @RequestMapping("/zj/{idsize}/{size}/{sizeNumber}")
    public String zj(@PathVariable("idsize") int idsize,@PathVariable("size") String size,@PathVariable("sizeNumber") int sizeNumber){
        String msg="增加尺码成功";
        Gsize gsize=new Gsize();
        gsize.setIdgsize(idsize);
        gsize.setSize(size);
        gsize.setSizeNumber(sizeNumber);



        try{
            gsizeDao.save(gsize);
        }catch (Exception e){
            msg="增加尺码失败";
        }
        return msg;
    }

    @RequestMapping("/update/{id}/{idsize}/{gsizezt}/{size}/{sizeNumber}")
    public String update(@PathVariable("id") int id,@PathVariable("idsize") int idsize,@PathVariable("size")  String size,@PathVariable("gsizezt")  int gsizezt,@PathVariable("sizeNumber")  int sizeNumber){
        String msg="修改尺码成功";
        Gsize gsize=gsizeDao.getOne(id);
        gsize.setIdgsize(idsize);
        gsize.setGsizezt(gsizezt);
        gsize.setSize(size);
        gsize.setSizeNumber(sizeNumber);


        try {
            gsizeDao.save(gsize);
        }catch (Exception e){
            msg="修改尺码失败";
        }
        return msg;
    }

    @RequestMapping("delete/{id}")
    public String delete(@PathVariable("id") int id){
        String msg="删除尺码成功";

        try {
            gsizeDao.delete(id);
        }catch (Exception e){
            msg="删除尺码失败";
        }
        return msg;
    }
}
